package com.zc.iotDevice.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.zc.iotDevice.domain.ChargeStationProduct;
import com.zc.iotDevice.service.ChargeStationProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/station/product")
public class ChargeStationProductController extends BaseController {

    @Autowired
    private ChargeStationProductService  productService;

    /**
     * 查询列表
     */
    @PreAuthorize("@ss.hasPermi('station:product:list')")
    @GetMapping("/list/{categoryId}")
    public AjaxResult listOfCategoryId(@PathVariable String categoryId)
    {
        return AjaxResult.success(productService.listOfCategoryId(categoryId));
    }

    /**
     * 查询
     */
    @PreAuthorize("@ss.hasPermi('station:product:info')")
    @GetMapping("/{id}")
    public AjaxResult info(@PathVariable String id)
    {
        return AjaxResult.success(productService.selectByPrimaryKey(id));
    }

    /**
     * 新增
     * @param product 新整参数
     * @return 新增操作结果
     */
    @PreAuthorize("@ss.hasPermi('station:product:add')")
    @Log(title = "新增产品", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody ChargeStationProduct product) {
        return toAjax(productService.insert(product));
    }

    /**
     * 修改
     * @param product 修改参数
     * @return 修改操作结果
     */
    @PreAuthorize("@ss.hasPermi('station:product:edit')")
    @Log(title = "修改产品", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody ChargeStationProduct product) {
        return toAjax(productService.updateByPrimaryKeySelective(product));
    }

    /**
     * 删除
     * @param id id
     * @return 删除操作结果
     */
    @PreAuthorize("@ss.hasPermi('station:product:remove')")
    @Log(title = "删除", businessType = BusinessType.DELETE)
    @DeleteMapping("{id}")
    public AjaxResult remove(@PathVariable String id) {
        return toAjax(productService.deleteByPrimaryKey(id));
    }
}
